﻿using System.Windows;

using EMan.Common.DependencyInjection;
using EMan.Interface.EnterpriseStructure;
using EMan.Interface.EnterpriseStructure.Departments;
using EMan.Interface.EnterpriseStructure.Employees;

using TrueCode.Core.Aspects;

namespace EMan.GUI.EditStructure
{
  /// <summary>
  /// Interaction logic for StructureTreeEditorView.xaml
  /// </summary>
  public partial class StructureTreeEditorView : IStructureTreeEditorView
  {
    public StructureTreeEditorView( [NotNull] IFactory factory, [NotNull] IStructureTreeEditorPresenter presenter ) : base( factory, presenter )
    {
      InitializeComponent();
    }

    public bool EditDepartment( DepartmentEditable department )
    {
      return ShowEditor( Factory.Resolve< IDepartmentEditorGuiElement >( department ) );
    }

    public bool EditEmployee( EmployeeEditable employee )
    {
      return ShowEditor( Factory.Resolve< IEmployeeEditorGuiElement >( employee ) );
    }

    private void CreateDepartmentButton_Click(object sender, RoutedEventArgs e)
    {
      Presenter.CreateDepartment();
    }

    private void CreateEmployeeButton_Click(object sender, RoutedEventArgs e)
    {
      Presenter.CreateEmployee();
    }

    private void OnEditButton_Click(object sender, RoutedEventArgs e)
    {
      Presenter.EditEntity();
    }

    private void OnSaveButton_Click(object sender, RoutedEventArgs e)
    {
      Presenter.Save();
    }

    private void OnTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
    {
      Presenter.SelectedItem = e.NewValue;
    }

    private void OnDeleteButton_Click( [NotNull] object sender, RoutedEventArgs e)
    {
      Presenter.Delete();
    }
  }
}